﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIA.Presentation.Contracts;
using VIA.Presentation;
using VIA.Project.Presentation.ViewModel.Inspection;
using VIA.SiMoJi.Domain.Inspection;
using VIA.Integration.Presentation;
using VIA.SiMoJi.Domain.Option;
using VIA.Foundation;

namespace VIA.SiMoJi.Presentation.ViewModel
{
    [ViewModel(typeof(ISiMoStationOptionView))]
    internal class SiMoStationOptionViewModel : EditorViewModel<ISiMoStationOptionView, SiMoStationOption>
    {
        private CylinderDebugViewModel cM_Jaw1;
        private CylinderDebugViewModel cM_Jaw2;
        private CylinderDebugViewModel cM_Jaw3;
        private CylinderDebugViewModel cM_Jaw4;
        private CylinderDebugViewModel cM_Jaw5;
        private CylinderDebugViewModel cM_Jaw6;
        private CylinderDebugViewModel cM_Jaw7;
        private CylinderDebugViewModel feeder_YaMoCM1;
        private CylinderDebugViewModel feeder_YaMoCM2;
        private CylinderDebugViewModel feeder_DingWeiCM1;
        private CylinderDebugViewModel feeder_DingWeiCM2;
        private double distance;

        public IRelayCommand FoawordStepCommand1 { get; set; }
        public IRelayCommand FoawordStepCommand2 { get; set; }

        public CylinderDebugViewModel CM_Jaw1 { get => cM_Jaw1; set => SetProperty(ref cM_Jaw1, value); }
        public CylinderDebugViewModel CM_Jaw2 { get => cM_Jaw2; set => SetProperty(ref cM_Jaw2, value); }
        public CylinderDebugViewModel CM_Jaw3 { get => cM_Jaw3; set => SetProperty(ref cM_Jaw3, value); }
        public CylinderDebugViewModel CM_Jaw4 { get => cM_Jaw4; set => SetProperty(ref cM_Jaw4, value); }
        public CylinderDebugViewModel CM_Jaw5 { get => cM_Jaw5; set => SetProperty(ref cM_Jaw5, value); }
        public CylinderDebugViewModel CM_Jaw6 { get => cM_Jaw6; set => SetProperty(ref cM_Jaw6, value); }
        public CylinderDebugViewModel CM_Jaw7 { get => cM_Jaw7; set => SetProperty(ref cM_Jaw7, value); }
        public CylinderDebugViewModel Feeder_YaMoCM1 { get => feeder_YaMoCM1; set => SetProperty(ref feeder_YaMoCM1, value); }
        public CylinderDebugViewModel Feeder_YaMoCM2 { get => feeder_YaMoCM2; set => SetProperty(ref feeder_YaMoCM2, value); }
        public CylinderDebugViewModel Feeder_DingWeiCM1 { get => feeder_DingWeiCM1; set => SetProperty(ref feeder_DingWeiCM1, value); }
        public CylinderDebugViewModel Feeder_DingWeiCM2 { get => feeder_DingWeiCM2; set => SetProperty(ref feeder_DingWeiCM2, value); }
        public SiMoStation Station { get; }
        public Feeder Feeder1 { get; }
        public Feeder Feeder2 { get; }
        public double Distance { get => distance; set => SetProperty(ref distance, value); }
        public SiMoStationOptionViewModel(IServiceProvider service, Inspector inspector) : base(service)
        {
            Station = inspector.SiMoStation;
            Feeder1 = Station.Feeder1;
            Feeder2 = Station.Feeder2;
            CM_Jaw1 = new(Station.Jaw1_Cylinder);
            CM_Jaw2 = new(Station.Jaw2_Cylinder);
            CM_Jaw3 = new(Station.Jaw3_Cylinder);
            CM_Jaw4 = new(Station.Jaw4_Cylinder);
            CM_Jaw5 = new(Station.Jaw5_Cylinder);
            CM_Jaw6 = new(Station.Jaw6_Cylinder);
            CM_Jaw7 = new(Station.Jaw7_Cylinder);
            Feeder_YaMoCM1 = new(Station.Feeder1.YaLiao_Cylinder) { Name = "飞达1压料气缸" };
            Feeder_YaMoCM2 = new(Station.Feeder2.YaLiao_Cylinder) { Name = "飞达2压料气缸" };
            Feeder_DingWeiCM1 = new(Station.Feeder1.DingWei_Cylinder) { Name = "飞达1固定气缸" };
            Feeder_DingWeiCM2 = new(Station.Feeder2.DingWei_Cylinder) { Name = "飞达2固定气缸" };
            FoawordStepCommand1 = _commandFactory.Create(FoawordStep1);
            FoawordStepCommand2 = _commandFactory.Create(FoawordStep2);
        }

        private async void FoawordStep1()
        {
            await Feeder1.AxisMoveAsync(Distance);
        }

        private async void FoawordStep2()
        {
            await Feeder2.AxisMoveAsync(Distance);
        }
    }
}
